package com.it.nongchanping.controller;

import com.it.nongchanping.service.AnnouncementService;
import com.it.nongchanping.service.NewsService;
import com.it.nongchanping.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private ProductService productService;

    @Autowired
    private NewsService newsService;

    @Autowired
    private AnnouncementService announcementService;

    @GetMapping({"", "/"})
    public String redirectToDashboard() {
        return "redirect:/admin/dashboard";
    }

    @GetMapping("/dashboard")
    public String dashboard(Model model) {
        model.addAttribute("title", "仪表盘");
        model.addAttribute("activePage", "dashboard");
        
        // 添加统计数据
        model.addAttribute("productCount", productService.countAllProducts());
        model.addAttribute("newsCount", newsService.countAllNews());
        model.addAttribute("announcementCount", announcementService.countAllAnnouncements());
        
        return "admin/dashboard";
    }
} 